package com.example.questionbase.config;


import com.example.questionbase.interceptor.AuthorizeInterceptor;
import com.example.questionbase.interceptor.UserInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class InterceptorRegisterConfig implements WebMvcConfigurer {

    /**
     * 把我们定义的拦截器类注册为Bean
     */
    @Bean
    public HandlerInterceptor getLoginInterceptor() {
        return new AuthorizeInterceptor();
    }

    @Bean
    public HandlerInterceptor getUserInterceptor() {
        return new UserInterceptor();
    }

    /**
     * 添加拦截器，并配置拦截地址
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        List<String> pathPatterns = new ArrayList<>();
//        pathPatterns.add("/*/login");
//        pathPatterns.add("/user/*");
//        pathPatterns.add("/question/*");
//        registry.addInterceptor(getLoginInterceptor()).excludePathPatterns(pathPatterns);
//        registry.addInterceptor(getUserInterceptor()).addPathPatterns("/user/*");
    }
}
